const {
  houseList_mock
} = require("../../../mock/house.js")
const {
  baseUrl,
  getRequest,
  postRequest
} = require("../../../utils/request.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //房源列表
    houseList: [],
    search: '',
    page: 1,
    size: 10,
    //条件筛选 
    value1: 0,
    option1: [{
        text: '附近',
        value: 0
      },
      {
        text: '商圈',
        value: 1
      },
      {
        text: '地铁',
        value: 2
      },
    ],
    value2: '0',
    option2: [{
        text: '合租',
        value: '0'
      },
      {
        text: '整租',
        value: '1'
      },
    ],
    //租金
    currentValue: 1000,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    //console.log(options.id)
    this.setData({
      search: options.id,
      //houseList: houseList_mock
    })
    this.http_house()
  },
  /**
   * 上拉刷新事件
   */
  onReachBottom() {
    //console.log("上拉刷新")
    //老数据合并新数据做累加操作
    this.setData({
      page: this.data.page + 1
    })
    this.http_house()
  },
  /**
   * 搜索栏点击事件
   */
  onSearchClick() {
    wx.navigateTo({
      url: '/pages/search/index/index',
    })
  },
  /**
   * 租金选择
   */
  onDrag(event) {
    this.setData({
      currentValue: event.detail.value,
    });
  },
  //查询房源
  http_house() {
    getRequest(baseUrl + "/front/house/search", {
        search: this.data.search,
        page: this.data.page,
        size: this.data.size,
      })
      .then(res => {
        console.log(res.data);
        if (res.code == 200) {
          this.setData({
            //老数据合并新数据做累加操作
            houseList: this.data.houseList.concat(res.data.records)
          })
        }
      })
  },
})